import logging
import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from Page1 import Page1
from ddt import ddt,file_data
from Tools import Tools

@ddt
class Case(unittest.TestCase):
    def setUp(self):
        print('start case')
        Tools().Log()
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()

    def tearDown(self):
        print('end case')
        time.sleep(5)
        self.driver.quit()

    @file_data('data.json')
    def test_01(self,name,exp):
        po = Page1(self.driver)
        logging.info('start case test_01')
        po.login_luoji()
        # po.open_url('http://localhost:8081/lxyk2list')
        # time.sleep(2)
        po.alert()
        time.sleep(2)
        # 断言1-员工姓名
        dy1 = self.driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section/main/div[1]/div[1]/div[1]/div[2]/table/thead/tr/th[3]/div').text
        print('断言1：',dy1)
        self.assertEquals('员工姓名',dy1)
        time.sleep(2)
        if exp == '正向用例':
            # 1.输入姓名-搜索框
            po.name(name)
            # 2.点击搜索
            po.search()
            time.sleep(2)
            # 断言2-刘哈哈ffgw
            dy2 = self.driver.find_element(By.XPATH,
                                           '/html/body/div[1]/div/section/section/main/div[1]/div[1]/div[1]/div[3]/div/div[1]/div/table/tbody/tr[1]/td[3]/div').text
            print('断言2：', dy2)
            self.assertEquals('刘哈哈ffgw', dy2)
            logging.info('end case test_01')
        else:
            # 1.输入姓名-搜索框
            po.name(name)
            # 2.点击搜索
            po.search()
            time.sleep(2)
            # # 断言2-暂无数据
            # dy2 = self.driver.find_element(By.LINK_TEXT,
            #                                '暂无数据').text
            # print('断言2：', dy2)
            # self.assertEquals('暂无数据', dy2)
            logging.info('end case test_01')


if __name__ == '__main__':
    unittest.main()
